<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/mui.js"></script>
		<script src="./utils/myRequest.js"></script>
		<!-- 		<style>
			#imgs {
				display: flex;
				justify-content: space-around;
				flex-wrap: wrap;
				align-items: center;
				margin-bottom: 20px;
			}

			.mi-img {
				flex: 3;
			}

			#imgs img {
				width: 100px;
			}
		</style> -->
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				var files = []; //用来保存需要上传的文件信息
				var user = store.getItem();
				//打开本地相册
				document.getElementById("btnUpload").addEventListener("tap", function() {
					var content = document.getElementById("content").value;
						plus.gallery.pick(function(path) {
							console.log(JSON.stringify(path));
							var task = plus.uploader.createUpload(url.base_url +
								"/websocket/t-article/sendArticle", {},
								function(t, status) {
									// console.log(JSON.stringify(t));
									var resp = t.responseText;
									// console.log(resp);
									// console.log(typeof resp.code);
									resp = JSON.parse(resp)
									// console.log(typeof resp);
									// 上传完成
									if (resp.code == 20000) {

										plus.nativeUI.toast(resp.message);

										//跳转到发现页面
										plus.webview.open("./wechat.html","wechat.html");
										//关闭当前页面
										plus.webview.currentWebview().close();



									} else {
										plus.nativeUI.toast(resp.message)
									}
								}
							);
							
							var files = path.files;
							
							for (var i = 0; i < files.length; i++) {
								var f = files[i];
								task.addFile(f, {
									key: "file" + i
								});
							}
							
							task.addData("userId", user.id + "");
							task.addData("content", content);
							task.start();

						}, function(e) {
							console.log("取消选择图片");
						}, {filter:"image",multiple:true});

					

				});
				
			});
		</script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">写说说</h1>
		</header>
		<div style="margin-top: 50px;">
			<div>
				<textarea id="content" style="width: 100%;height: 250px;">你此时想说些什么...</textarea>
			</div>

			<div id="sheet" class="mui-popover mui-popover-bottom mui-popover-action">
				<!-- 可选择菜单 -->
				<ul class="mui-table-view">
					<li class="mui-table-view-cell" id="btnUpload">
						<a href="#">从相册选择</a>
					</li>
					<li class="mui-table-view-cell">
						<a href="#">照相机</a>
					</li>
				</ul>
				<!-- 取消菜单 -->
				<ul class="mui-table-view">
					<li class="mui-table-view-cell" id="reloadBtn">
						<a href="#sheet1"><b>取消</b></a>
					</li>
				</ul>
			</div>
			<a href="#sheet" id="openSheet" class="mui-btn mui-btn-primary mui-btn-block" style="">发布</a>

		</div>
		<!--分享的图片-->
		<!-- 	<div id="imgs">
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s1_m.jpg" />
				</a>
			</div>
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s2_m.jpg" />
				</a>
			</div>
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s3_m.jpg" />
				</a>
			</div>
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s4_m.jpg" />
				</a>
			</div>
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s5_m.jpg" />
				</a>
			</div>
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s3_m.jpg" />
				</a>
			</div>
			<div class="mi-img">
				<a href="#" data-size="800x1142">
					<img src="images/s3_m.jpg" />
				</a>
			</div>
		</div>
 -->
		<!-- <div>
			<ul class="mui-table-view"
				style="text-align: center;color: white;background-color: green;margin-bottom: 10px;">
				<li class="mui-table-view-cell mui-media" id="searchResultBtn">
					<a href="javascript:;">
						发布
					</a>
				</li>
			</ul>
		</div> -->

		</div>

	</body>

</html>
